<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2024/9/4
  Time: 9:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Space</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/bootstrap-fileinput/4.4.7/css/fileinput.min.css" media="all" rel="stylesheet"
          type="text/css"/>
    <link rel="stylesheet" href="./css/style.css">

</head>
<body>
<div id="wrapper" class="toggled">
    <nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">
        <ul class="nav sidebar-nav">
            <li class="sidebar-brand">
                <a href="/productList">
                    商家管理系统
                </a>
            </li>
            <li class="sidebar-brand">
                <a href="#">
                    您好, ${username}
                </a>
            </li>
            <li>
                <a href="/userServlet"><i class="fa fa-fw fa-list-alt"></i> 用户管理</a>
            </li>
            <li>
                <a href="/AddUserServlet"><i class="fa fa-fw fa-list-alt"></i> 新增用户</a>
            </li>
            <li class="dropdown open">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true"><i
                        class="fa fa-fw fa-plus"></i> 商品 <span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    <li class="dropdown-header">操作</li>
                    <li><a href="/productListServlet">列表</a></li>
                    <li><a href="/addProductServlet">新增</a></li>
                </ul>
            </li>
            <li class="dropdown open">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
                    <i class="fa fa-fw fa-plus"></i> 类目 <span class="caret"></span>
                </a>
                <ul class="dropdown-menu" role="menu">
                    <li class="dropdown-header">操作</li>
                    <li><a href="/categoryListServlet">列表</a></li>
                    <li><a href="/AddproductServlet">新增</a></li>
                </ul>
            </li>

            <li>
                <a href=""><i class="fa fa-fw fa-list-alt"></i> 登出</a>
            </li>
        </ul>
    </nav>
    <div id="page-content-wrapper">
        <div class="container-fluid">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <h3 style="text-align: left"><a href="#">商品信息列表</a></h3>
                    <form class="form-inline" action="/productListServlet" method="post">
                        <div class="form-group">
                            <label>商品名称</label>
                            <%--                            name往里面传值--%>
                            <input type="text" name="product_name" class="form-control" value="${product_name}">
                        </div>
                        <div class="form-group">
                            <label>商品类目名称</label>
                            <input type="text" name="category_type" class="form-control" value="${category_type}">
                        </div>
                        <div class="form-group">
                            <label>商品状态</label>
                            <c:if test="${product_status==null ||product_status==undefined  }">
                                <select name="product_status" class="form-control" style="width: 300px" >
                                    <option value="" selected="selected">
                                        请选择
                                    </option>
                                    <option value="0" >
                                        正常
                                    </option>
                                    <option value="1" >
                                        下架
                                    </option>
                                </select>
                            </c:if>
                            <c:if test="${product_status==0  }">
                                <select name="product_status" class="form-control" style="width: 300px" >
                                    <option value="" >
                                        请选择
                                    </option>
                                    <option value="0" selected="selected">
                                        正常
                                    </option>
                                    <option value="1" >
                                        下架
                                    </option>
                                </select>
                            </c:if>
                            <c:if test="${product_status==1 }">
                                <select name="product_status" class="form-control" style="width: 300px" >
                                    <option value="" >
                                        请选择
                                    </option>
                                    <option value="0" >
                                        正常
                                    </option>
                                    <option value="1" selected="selected">
                                        下架
                                    </option>
                                </select>
                            </c:if>
                        </div>
                        <button type="submit" class="btn btn-success">查询</button>
                    </form>
                    <table class="table table-bordered table-condensed">
                        <thead>
                        <tr class="right">
                            <th>ID</th>
                            <th>商品名称</th>
                            <th>商品价格</th>
                            <th>商品库存</th>
                            <th>商品描述</th>
                            <th>商品状态</th>
                            <th>商品类目编号</th>
                            <th>创建时间</th>
                            <th>修改时间</th>
                            <%--                            合并两列--%>
                            <th colspan="2">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <%--                      ${}  从后端往前端传值  --%>
                        <c:forEach var="product" items="${pb.list}" varStatus="loop">
                            <c:choose>
                                <c:when test="${loop.index %2==1}">
                                    <tr class="warning">
                                        <td>${product.product_id}</td>
                                        <td>${product.product_name}</td>
                                        <td>${product.product_price}元</td>
                                        <td>${product.product_stock}</td>
                                        <td>${product.product_description}</td>
                                        <td>
                                            <c:if test="${product.product_status==0}">
                                                <a href="/productOperateServlet?product_id=${product.product_id}&product_status=${product.product_status}&operate=product_status ">正常</a>
                                            </c:if>
                                            <c:if test="${product.product_status==1}">
                                                <a href="/productOperateServlet?product_id=${product.product_id}&product_status=${product.product_status}&operate=product_status ">下架</a>
                                            </c:if>
                                        </td>
                                        <td>${product.category_type}</td>
                                        <td>${product.create_time}</td>
                                        <td>${product.update_time}</td>
                                        <td><a href="/productOperateServlet?product_id=${product.product_id}&operate=del">删除</a>
                                        </td>
                                        <td><a href="/productOperateServlet?product_id=${product.product_id}&operate=update">修改</a>
                                        </td>
                                    </tr>
                                </c:when>
                                <c:otherwise>
                                    <tr class="success">
                                        <td>${product.product_id}</td>
                                        <td>${product.product_name}</td>
                                        <td>${product.product_price}元</td>
                                        <td>${product.product_stock}</td>
                                        <td>${product.product_description}</td>
                                        <td>
                                            <c:if test="${product.product_status==0}">
                                                <a href="/productOperateServlet?product_id=${product.product_id}&product_status=${product.product_status}&operate=product_status ">正常</a>
                                            </c:if>
                                            <c:if test="${product.product_status==1}">
                                                <a href="/productOperateServlet?product_id=${product.product_id}&product_status=${product.product_status}&operate=product_status ">下架</a>
                                            </c:if>
                                        </td>
                                        <td>${product.category_type}</td>
                                        <td>${product.create_time}</td>
                                        <td>${product.update_time}</td>
                                        <td><a href="/productOperateServlet?product_id=${product.product_id}&operate=del">删除</a>
                                        </td>
                                        <td><a href="/productOperateServlet?product_id=${product.product_id}&operate=update">修改</a>
                                        </td>
                                    </tr>
                                </c:otherwise>
                            </c:choose>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>

                <!--                分页-->
                <div class="col-md-12 column">
                    <ul class="pagination align-center">
                        <c:if test="${pb.currentPage==1}" >
                            <li><a class="disabled" href="#">上一页</a></li>
                        </c:if>
<%--                        修改条件让其大于1的时候减1--%>
                        <c:if test="${pb.currentPage>1}" >
                            <li> <a href="/productListServlet?currentPage=${pb.currentPage-1}&product_name=${product_name}&category_type=${category_type}">上一页</a> </li>
                        </c:if>
                        <c:forEach begin="1" end="${pb.totalPages}" var="i">
                            <%--              当前页有特殊效果--%>
                            <c:if test="${pb.currentPage==i}">
                                <li class="active"> <a href="/productListServlet?currentPage=${i}&product_name=${product_name}&category_type=${category_type}">${i}</a> </li>
                            </c:if>
                            <%--              其他页--%>
                            <c:if test="${pb.currentPage!=i}">
                                <li> <a  href="/productListServlet?currentPage=${i}&product_name=${product_name}&category_type=${category_type}">${i}</a> </li>
                            </c:if>
                        </c:forEach>
                        <%--            下一页--%>
                        <c:if test="${pb.currentPage==pb.totalPages}" >
                            <li><a class="disabled" href="#">下一页</a></li>
                        </c:if>
<%--                        小于总页数的时候+1--%>
                        <c:if test="${pb.currentPage<pb.totalPages}" >
                            <li> <a href="/productListServlet?currentPage=${pb.currentPage+1}&product_name=${product_name}&category_type=${category_type}">下一页</a> </li>
                        </c:if>
                    </ul>

                </div>
            </div>
        </div>
    </div>

</div>
</body>
</html>
